package com.zhichat.infrastructure.util;

import cn.hutool.core.util.ObjectUtil;
import com.zhichat.web.dto.UserToken;

public final class ThreadLocalCache {

    private static final ThreadLocal<UserToken> USERCACHE = new ThreadLocal<>();

    public static void putUserToken(UserToken model) {
        USERCACHE.set(model);
    }

    public static UserToken getUserToken() {
        return USERCACHE.get();
    }

    public static Long getUserId() {
        UserToken token = getUserToken();
        if (ObjectUtil.isNotNull(token)) {
            return token.getUserId();
        }
        return null;
    }

    public static void clear() {
        USERCACHE.remove();
//        CANREDS.remove();
    }
}
